/*
* $Id: TableHeader.cpp 152 2010-09-23 18:28:55Z volok-aleksej@yandex.ru $
*
* Copyright 2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "Xml/TableXml.h"
#include "TableHeader.h"

CTableHeader::CTableHeader(const std::tstring& strName, int nId, TypeField::type tp)
: tableHeader(strName, nId, tp), CItemTable(CCommonFunction::GetBeeColor()){
	int cx = GetXmlCx();
	m_size = GetDefaultSize(cx);
}
CTableHeader::~CTableHeader(){
	SetXmlCx();
}

void CTableHeader::SetPos(CPoint pos, bool bNextParent){
	CSize diffSize = m_pos - pos;
	m_pos = pos;
	if(m_pNext){
		CPoint posNext = ((CTableHeader*)m_pNext)->GetPos();
		((CTableHeader*)m_pNext)->SetPos(CPoint(m_pos.x + m_size.cx, posNext.y), bNextParent);
	}
}

void CTableHeader::SetSize(CSize size){
	m_size = size;
}

bool CTableHeader::IsInRect(CPoint pos){
	return pos.x > m_pos.x && pos.y > m_pos.y &&
		pos.x < m_pos.x + m_size.cx - 2 && pos.y < pos.y + m_size.cy;
}

bool CTableHeader::IsAtBorder(CPoint pos){
	return pos.x > m_pos.x + m_size.cx - 2 && pos.y > m_pos.y &&
		pos.x < m_pos.x + m_size.cx + 2 && pos.y < m_pos.y + m_size.cy;
}

int CTableHeader::GetXmlCx(){
	return g_tableXml.GetHeaderCx(m_nId);
}

void CTableHeader::SetXmlCx(){
	g_tableXml.SetHeaderCx(m_nId, m_size.cx);
}